﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;
using Yule8xModel.PageModels;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Payment.BaifuPay
{
    public partial class noticeQuery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 百付第三方支付return.aspx中回调商户通知地址
            string out_trade_no = RequestUtil.ParamsString("out_trade_no");

            string sqlstmt = string.Format("select top 1 paramstr from t_finance_recharge where out_trade_no='{0}'", out_trade_no);
            string attach = DbFactory.Init(AppInfo.conn_yule8x_agent).GetValue(sqlstmt, string.Empty).ToString();

            string outmsg;
            if (attach.IndexOf("buydiamond:") > -1)
            {
                int rebate_amount = AppConf.AgentRegistReturnAmount;
                decimal parent1_commission_rate = AppConf.Parent1AgentCommissionRate; // 上级是代理, 获得25%返佣
                decimal parent2_commission_rate = AppConf.Parent2AgentCommissionRate; // 上上级是代理, 获得15%返佣

                WxPayResultNotifyPageModels.BuyCardPay(out_trade_no, rebate_amount, parent1_commission_rate, parent2_commission_rate, out outmsg);
                Response.Write("true");
            }
            else if (attach.IndexOf("agentregist:") > -1)
            {
                int number = AppConf.AgentRegistCardCount; // 注册成为代理购买钻石数量
                decimal amount = AppConf.AgentRegistCardAmount; // 注册成为代理付款金额
                int rebate_amount = AppConf.AgentRegistReturnAmount;
                decimal parent1_commission_rate = AppConf.Parent1AgentCommissionRate; // 上级是代理, 获得25%返佣
                decimal parent2_commission_rate = AppConf.Parent2AgentCommissionRate; // 上上级是代理, 获得15%返佣
                WxPayResultNotifyPageModels.AgentRegistPay(out_trade_no, attach, number, amount, rebate_amount, parent1_commission_rate, parent2_commission_rate, out outmsg);
                Response.Write("true");
            }
            Response.Write("true");
        }
    }
}